#!/bin/sh
num=`cat /etc/issue|grep 6|wc -l`
[ $num -eq 0 ] && echo "not rh6" && exit 9
fnum=`lspci |grep -i 'fusion-io'|wc -l`
if [ $fnum -gt 0 ];then
	yum install -b test -y fio-common-3.1.5.126-1.0.el6.x86_64  fio-sysvinit-3.1.5.126-1.0.el6.x86_64  fio-util-3.1.5.126-1.0.el6.x86_64
	yum install -b test -y iomemory-vsl-2.6.32-220.17.1.tb619.el6.x86_64-3.1.5.126-1.0.el6.x86_64 iomemory-vsl-config-2.6.32-220.17.1.tb619.el6.x86_64-3.1.5.126-1.0.el6.x86_64 iomemory-vsl-source-3.1.5.126-1.0.el6.x86_64
    echo "options iomemory-vsl use_workqueue=0
    options iomemory-vsl disable-msi=0
    options iomemory-vsl use_large_pcie_rx_buffer=1
    ">> /etc/modprobe.d/iomemory-vsl.conf  
    modprobe iomemory-vsl
    num=`fio-status -a|grep 'active errors'|wc -l`
    if [ $num -gt 0 ];then
        yum install -b test -y fio-firmware-3.20120525-1.0
    	fio-update-iodrive `rpm -ql fio-firmware |tail -n 1`
        echo "sleep 300
        num=\`fio-status -a|grep 'active errors'|wc -l\`
        if [ \$num -gt 0 ];then
        	fio-detach /dev/fct0 
        	fio-format /dev/fct0 -y
        	fio-attach /dev/fct0 
        fi
        yum install -b test -y flashcache.x86_64
        umount /u01
        sed  -ie '/[uU]01/ s/^/#/g' /etc/fstab   #这里要留意
        flashcache_create -p back cachedev /dev/fioa /dev/sdb1
        mount -o noatime,nodiratime,barrier=0 /dev/mapper/cachedev  /u01
        sed -i s:sdb1.cache_all=0:sdb1.cache_all=1:g /etc/sysctl.conf
        sysctl -p

        if [ \$? -eq 0 ] ;then
        	rm -rf /tmp/setup_fio.sh
        	#echo "ln -sf  /home/mysql/agent/bin/mysqldauto_uic /etc/rc.d/rc3.d/S99mysqld " >> /etc/rc.local
        	sed  -ie '/setup_fio/ s/^/#/g' /etc/rc.local
        fi
        "  > /tmp/setup_fio.sh
        chmod +x /tmp/setup_fio.sh
        echo "sh /tmp/setup_fio.sh" >> /etc/rc.local
        echo "This machine will reboot in 10 sec"
        echo "you can cancle it use Ctrl+C"
        sleep 10
        reboot
    else
        echo "Fiocard OK"
        ln -sf  /home/mysql/agent/bin/mysqldauto_uic /etc/rc.d/rc3.d/S99mysqld
        yum install -b test -y flashcache.x86_64
        umount /u01
        sed  -ie '/[uU]01/ s/^/#/g' /etc/fstab   #这里要留意
        flashcache_create -p back cachedev /dev/fioa /dev/sdb1
        mount -o noatime,nodiratime,barrier=0 /dev/mapper/cachedev  /u01
        sed -i s:sdb1.cache_all=0:sdb1.cache_all=1:g /etc/sysctl.conf
        sysctl -p
    fi
else 
	echo "no pcie-card"
	exit 0
fi